// API响应基础类型
export interface ApiResponse<T = any> {
  code: number
  message: string
  data: T
  success: boolean
  timestamp?: number
}

// 分页响应类型
export interface PaginatedResponse<T> extends ApiResponse<T[]> {
  pagination: {
    page: number
    pageSize: number
    total: number
    totalPages: number
  }
}

// 列表响应类型
export interface ListResponse<T> extends ApiResponse<T[]> {
  total: number
}

// 上传响应类型
export interface UploadResponse extends ApiResponse<{
  url: string
  filename: string
  size: number
  mimeType: string
}> {}

// 下载响应类型
export interface DownloadResponse {
  blob: Blob
  filename: string
  mimeType: string
}

// 请求配置类型
export interface RequestConfig {
  showLoading?: boolean
  showError?: boolean
  retryCount?: number
  retryDelay?: number
  timeout?: number
}

// 错误类型
export interface ApiError {
  code: number
  message: string
  details?: any
  timestamp: number
}

// 请求参数类型
export interface RequestParams {
  [key: string]: any
}

// 查询参数类型
export interface QueryParams extends RequestParams {
  page?: number
  pageSize?: number
  sortBy?: string
  sortOrder?: 'asc' | 'desc'
  keyword?: string
  filters?: Record<string, any>
}

// 文件上传参数
export interface UploadParams {
  file: File
  onProgress?: (progress: number) => void
  onSuccess?: (response: UploadResponse) => void
  onError?: (error: ApiError) => void
}

// 文件下载参数
export interface DownloadParams {
  url: string
  filename?: string
  onProgress?: (progress: number) => void
  onSuccess?: (response: DownloadResponse) => void
  onError?: (error: ApiError) => void
}

// 认证相关类型
export interface LoginRequest {
  username: string
  password: string
  role: string
  rememberMe?: boolean
}

export interface LoginResponse extends ApiResponse<{
  token: string
  refreshToken: string
  user: {
    id: string
    username: string
    role: string
    name: string
    email: string
    avatar?: string
  }
}> {}

export interface RegisterRequest {
  username: string
  password: string
  confirmPassword: string
  role: string
  realName: string
  email: string
  phone: string
  organization?: string
  department?: string
  researchDirection?: string[]
}

export interface RefreshTokenRequest {
  refreshToken: string
}

export interface RefreshTokenResponse extends ApiResponse<{
  token: string
  refreshToken: string
}> {}

// 用户相关类型
export interface UserProfile {
  id: string
  username: string
  role: string
  name: string
  email: string
  phone: string
  avatar?: string
  organization?: string
  department?: string
  researchDirection?: string[]
  createdAt: string
  updatedAt: string
}

export interface UpdateProfileRequest {
  name?: string
  email?: string
  phone?: string
  avatar?: string
  organization?: string
  department?: string
  researchDirection?: string[]
}

// 项目相关类型
export interface ProjectRequest {
  title: string
  researchDirection: string[]
  description: string
  requirements: string
  deadline: string
  budget?: number
  contactPerson?: string
  contactPhone?: string
}

export interface ProjectResponse extends ApiResponse<{
  id: string
  title: string
  enterpriseId: string
  enterpriseName: string
  researchDirection: string[]
  description: string
  requirements: string
  deadline: string
  budget?: number
  status: string
  createdAt: string
  updatedAt: string
}> {}

// 申请相关类型
export interface ApplicationRequest {
  projectId: string
  researchPlan?: string
  resume?: string
}

export interface ApplicationResponse extends ApiResponse<{
  id: string
  projectId: string
  projectTitle: string
  applicantId: string
  applicantName: string
  applicantRole: string
  researchPlan?: string
  resume?: string
  status: string
  createdAt: string
  updatedAt: string
}> {}

// 统计相关类型
export interface StatisticsResponse extends ApiResponse<{
  totalProjects: number
  totalApplications: number
  totalMatches: number
  projectsByDiscipline: Record<string, number>
  applicationsByStatus: Record<string, number>
  matchesByMonth: Record<string, number>
}> {}
